<template>
  <!-- <div class="tab-bar-item" @click="itemClick">
    <div v-if="!isActive">
      <slot name="item-icon"></slot>
    </div>
    <div v-else>
      <slot name="itme-icon-active"></slot>
    </div>
    <div :style="activeStyle">
      <slot name="item-text"></slot>
    </div>
  </div> -->
  
  <div class="tab-bar-item"  @click="itemClick">
    <!-- 这个地方不能写死  所以又要搞插槽 -->
    <div v-if="!isActive">
      <slot name="item-icon"></slot>
    </div>
    <div v-else>
      <slot name="item-icon-active"></slot>
    </div>
    <div :style="activeStyle">
      <slot name="item-text"></slot>
    </div>
    

    <!-- <img src="../../../assets/img/logo.png" alt="">

    <div>首页</div> -->
  </div>
</template>


<script>
export default {
  name:'TabBarItem',
  // tab-bar-item传递过来的路径和动态传递的颜色
  props:{
    path:String,
    activeColor:{
      type:String,
      default:'red'
    }
  },
  data(){
    return{
      // isActive:true,
     
    }
  },
  computed:{
    isActive(){
      // 注意这里是$route 表示当前触发的路由
      return this.$route.path.indexOf(this.path) !==-1;
    },
    // 动态决定颜色
    activeStyle(){
      return this.isActive? {color:this.activeColor}:{}
    }
  },
  methods:{
    itemClick(){
      // 跳转路由  $router
      this.$router.push(this.path)
      console.log('CLICK');
    }
  }
}
</script>

<style scoped>
  .tab-bar-item {
    flex: 1;
    text-align: center;
    height: 49px;
    font-size: 14px;
  }
  .tab-bar-item img {
    width: 24px;
    height: 24px;
    margin-top:3px ;
    margin-bottom: 2px;
    vertical-align: middle;
  }
  .active {
    color: red;
  }
</style>
